package grpc

import (
	"gitee.com/lailonghui/vehicle-supervision-framework/pkg/services"
	"google.golang.org/grpc"
)

// 使用EndpointFinder创建客户端
func NewEnterpriseClientByFinder(finder services.EndpointFinder) (EnterpriseGrpcClient, error) {
	endpoint := finder.GetGrpcServerEndpoint("adm", "enterprise")
	return NewEnterpriseClient(endpoint)
}

// 使用endpoint创建客户端
func NewEnterpriseClient(endpoint string) (EnterpriseGrpcClient, error) {
	var opts []grpc.DialOption
	opts = append(opts, grpc.WithInsecure())
	opts = append(opts, grpc.WithBlock())
	conn, err := grpc.Dial(endpoint, opts...)
	if err != nil {
		return nil, err
	}
	client := NewEnterpriseGrpcClient(conn)
	return client, nil
}
